package gameserver.network.game;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ServerPacketsOpcodes
{
	private static Map<Class<? extends GameServerPacket>,Integer> opcodes = new HashMap<Class<? extends GameServerPacket>, Integer>();
	
	static
	{
		Set<Integer> idSet = new HashSet<Integer>();
		
	}
	
	private static void addPacketOpcode(Class<? extends GameServerPacket> packetClass,Integer opcode,Set<Integer> idSet)
	{
		if(opcode < 0)
			return;
		if(idSet.contains(opcode))
		{
			throw new IllegalArgumentException("duplicate opcode");
		}
		idSet.add(opcode);
		opcodes.put(packetClass, opcode);
	}
	
	static int getOpcode(Class<? extends GameServerPacket> packetClass)
	{
		Integer opcode = opcodes.get(packetClass);
		if(opcode == null)
			throw new IllegalArgumentException("There is no opcode for " + packetClass + " defined.");
		return opcode;
		
	}
}
